﻿Imports System
Imports System.Collections
Imports System.Configuration
Imports System.Data
Imports System.Linq
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Xml.Linq
Imports BBDD
Imports Controladores

 _

Class venderAccOper
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        If Session("privUser") Is Nothing Or Integer.Parse(Session("privUser").ToString()) < 1 Then
            Response.Redirect("index.aspx")
        Else
            If Integer.Parse(Session("privUser").ToString()) = 1 Then
                campoDNI.Text = Session("DNIUser").ToString()
                campoDNI.Enabled = False
                listaAcciones.Value = Consultas.listarCartera(Session("DNIUser").ToString())
                botonMostrarAcciones.Enabled = True
            Else
                campoDNI.Enabled = True
                botonMostrarAcciones.Enabled = True
            End If
        End If
    End Sub 'Page_Load

    Protected Sub boton_venderValor_Click(ByVal sender As Object, ByVal e As EventArgs)

        If campoCantidad.Text = "" Then
            campoCantidad.Text = "-1"
        End If

        If campoValor.Text = "" Then
            campoValor.Text = "-1"
        End If
        campoValor.Text.Replace(",", ".")
        Session("error") = controlador.venderAccionPorValor(campoDNI.Text.ToString(), campoSimbolo.Text.ToString(), Integer.Parse(campoCantidad.Text.ToString()), Double.Parse(campoValor.Text.ToString()))
        If Session("error").ToString() = "" Then
            Me.campoCantidad.Text = ""
            Me.campoSimbolo.Text = ""
            Me.campoValor.Text = ""
            controlador.CreateMessageAlert(Me, "Operacion llevada con éxito", "msg")

        Else
            controlador.CreateMessageAlert(Me, Session("error").ToString(), "msg")
        End If
    End Sub 'boton_venderValor_Click

    Protected Sub boton_mostrarAcciones_Click(ByVal sender As Object, ByVal e As EventArgs)
        Me.listaAcciones.Value = Consultas.listarCartera(campoDNI.Text.ToString())
    End Sub 'boton_mostrarAcciones_Click
End Class 'venderAccOper